package com.yitiao.dao;

import com.yitiao.entry.SpringCloud;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@AllArgsConstructor
@Repository
public class SpringCloudDaoImpl implements SpringCloudDao{
    private final MongoTemplate mongoTemplate;

    private final String COLLECTION_NAME = "spring_cloud";

    @Override
    public void addOne(SpringCloud cloud) {
        mongoTemplate.save(cloud, COLLECTION_NAME);
    }

    @Override
    public SpringCloud findById(String id) {
        return mongoTemplate.findById(id, SpringCloud.class, COLLECTION_NAME);
    }

    @Override
    public List<SpringCloud> findAll() {
        return mongoTemplate.findAll(SpringCloud.class, COLLECTION_NAME);
    }
}
